home *** CD-ROM | disk | FTP | other *** search
- /* PageSetup.c
- * Do the page setup dialog in Writeswell Jr.
- *
- * ©1992 Working Software, Inc.
- * This source code is copyrighted. Permission is granted to use the Word Services
- * portion of the Writeswell Jr. source code in your own programs, but you
- * may not distribute the Writeswell Jr. word-processor code as a
- * commercial product. If you modify the code, please do not call it
- * Writeswell Jr. (or Writeswell.) This will ensure that people understand the
- * program and don’t have to deal with a number of different versions with
- * who-knows-what going on in the code.
- *
- * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
- *
- * 24 Oct 92 Mike Crawford
- */
-
- #include <AppleEvents.h>
- #include <Printing.h>
- #include "TestBed.h"
- #include "TBConstants.h"
- #include "Gripe.h"
- #include "Prefs.h"
- #include "TBGlobals.h"
- #include "PageSetup.h"
-
- void DoPageSetup( void )
- {
- THPrint thePrRecHdl;
- OSErr printErr;
- Boolean saveSetup;
-
- thePrRecHdl = GetPrintRecord();
-
- if ( !thePrRecHdl ){
- Gripe( "\pCannot get print record" );
- return;
- }
-
- saveSetup = false;
-
- PrOpen();
-
- printErr = PrError();
-
- if ( printErr == noErr ){
-
- PrValidate( thePrRecHdl );
-
- printErr = PrError();
-
- if ( printErr == noErr ){
-
- saveSetup = PrStlDialog( thePrRecHdl );
-
- printErr = PrError();
-
- }
- }else{
- Gripe( "\pCould not open the printer driver" );
- }
- PrClose();
-
- if ( PrError() || printErr || !saveSetup ){
- ReleaseResource( (Handle) thePrRecHdl );
- thePrRecHdl = NULL;
- return;
- }
-
- ChangedResource( (Handle) thePrRecHdl );
- WriteResource( (Handle) thePrRecHdl );
- UpdateResFile( gPrefFileRefNum );
-
- return;
- }
-
- THPrint GetPrintRecord( void )
- {
- THPrint thePrRecHdl;
- short curFile;
- long prRecSize;
- OSErr err;
-
- /* DO NOT Call this function while the printer driver is open */
-
- curFile = CurResFile();
- UseResFile( gPrefFileRefNum );
-
- thePrRecHdl = (THPrint)Get1Resource( 'PStl', rPrintRecID );
-
- UseResFile( curFile );
-
- if ( thePrRecHdl ){
-
- /* Validate the the handle is a good one */
-
- prRecSize = GetHandleSize((Handle) thePrRecHdl );
- if ( prRecSize != sizeof( TPrint ) ){
- RmveResource( (Handle) thePrRecHdl );
- return (THPrint)NULL;
- }
-
- return thePrRecHdl;
- }
-
- /* At this point, no print record was found, so we create a new one */
-
- thePrRecHdl = (THPrint)NewHandleClear( sizeof( TPrint ) );
- if ( !thePrRecHdl )
- return (THPrint)NULL;
-
- /* Set the default values into the print record */
-
- PrOpen();
-
- if ( PrError() == noErr ){
-
- PrintDefault( thePrRecHdl );
-
- if ( PrError() != noErr ){
- DisposHandle( (Handle) thePrRecHdl );
- thePrRecHdl = (THPrint)NULL;
- }
- }else{
- DisposHandle( (Handle) thePrRecHdl );
- thePrRecHdl = (THPrint)NULL;
- }
- PrClose();
-
- if ( thePrRecHdl == (THPrint)NULL )
- return (THPrint)NULL;
-
- /* At this point, we have a good print record. Save it into the
- * preferences file
- */
-
- UseResFile( gPrefFileRefNum );
-
- AddResource( (Handle) thePrRecHdl, 'PStl', rPrintRecID, "\pPage Setup" );
-
- err = ResError();
-
- UseResFile( curFile );
-
- if ( err ){
- DisposHandle( (Handle) thePrRecHdl );
- return (THPrint)NULL;
- }
-
- WriteResource((Handle) thePrRecHdl );
- UpdateResFile( gPrefFileRefNum );
-
- return thePrRecHdl;
- }